package fdq.entity;

import fdq.mapper.FeatureMapper;
import fdq.utils.SqlSessionGet;
import org.apache.ibatis.session.SqlSession;

import java.util.ArrayList;
import java.util.List;

public class AnimalSet {

    private ArrayList<Animal> animalList;



    public ArrayList<Animal> getAnimalList() {
        return animalList;
    }

    public AnimalSet(ArrayList<Animal> animalList) {
        this.animalList = animalList;
    }

//    public void addAnimal(Animal newanimal){
//        animalList.add(newanimal);
//    }
//    public void deleteAnimal(){
//        System.out.println("deleteAnimal");
//    }



    //判断特征集中是否能满足某一个动物的全部特征,如果有就返回该动物
    public Animal isCorrespond(ArrayList<Feature> features){
        SqlSessionGet sqlSessionGet = new SqlSessionGet();
        SqlSession sqlSession = sqlSessionGet.getSqlsession();
        FeatureMapper featureMapper = sqlSession.getMapper(FeatureMapper.class);

        for(Animal a : animalList){
            ArrayList<Feature> featureByAnimal = featureMapper.selectFeatureByAnimal(a.getAid());
            boolean flag = Feature.featureInside(featureByAnimal, features);
            if(flag){
                return a;
            }
        }

        return null;
    }
}
